import java.util.Arrays;

public class Mystack {
    int[] elems;
    int useSize;
    public Mystack(){
        this.elems = new int[5];
    }
    public void push(int val){
        checkCapacity();
        this.elems[this.useSize] = val;
        this.useSize++;
    }

    public int pop(){
        int e = peek();
        this.elems[this.useSize-1] = 0;
        //this.elems[this.useSize-1] = null;
        useSize--;
        return e;
    }
    public int peek(){
        if(isEmpty()){
            System.out.println("栈为空");
            return -1;
        }
        return elems[useSize-1];
    }
    private boolean isEmpty(){
        return useSize==0;
    }

    private void checkCapacity(){
        if(this.useSize==this.elems.length){
            Arrays.copyOf(this.elems,2*this.useSize);
        }
    }
}
